/**邮箱验证*/
var countdown=60;
var email=GetRequest().email;
var timer=null;
function GetRequest() {
    var url = decodeURI(location.search);
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
$(function (){
	/*var object = GetRequest();*/
	var sweetcookie = new sweetCookie();
    var email=sweetcookie.getCookie("email");
	if(email==null){
		location.href="/Lvscore_Advertiser_Maven/advertiserWeb/views/login/E-mail.html";
	}
	$("#email").text(email);
	$("#loginin").on("click",function(){
		var useremail=$("#email").html();
		var emailCate=useremail.split("@")[1];
		window.open("http://mail."+emailCate);
	});
	
	//点击重新获取的事件
	$("#btn").on("click",function(){
		countdown=60;
		var object = GetRequest();
		var email = object.email;
		timer=setInterval(settime, 1000);
		$.ajax({ 
	 		type:"post",
			url:"/Lvscore_Advertiser_Maven/sendEmail",
		    data: {"email": email},
	        dataType:'json',
		    success : function(data) {
		    	console.log("成功");
		    },
	        error: function(data){
	        	console.log("失败"+data);
	        }     
		});
	})
})


function settime(){
	$("#btn").addClass("getCodeAgain");
	$("#btn").attr("disabled",true);
	var object = GetRequest();
	countdown--;
	$("#btn").val(countdown+'s');
	if (countdown <= 0) {
		$("#btn").attr("disabled",false);
		$("#btn").removeClass("getCodeAgain");
		$("#btn").val("重新获取");
		clearInterval(timer);
	} 
}


function next(){
	$.ajax({ 
 		type:"post",
		url:"/Lvscore_Advertiser_Maven/findCode",
	    data: {},
        dataType:'json',
	    success : function(data) {
		     var verificationCode=$("#verificationCode").val();
		     if(data.verCode!=verificationCode){
		    	 $("#alertspan").show();
		    	 $("#verificationCode").on("focus",function(){
		    		 $("#alertspan").hide(); 
		    	 })
		     }else{
		    	 location.href="/Lvscore_Advertiser_Maven/advertiserWeb/views/login/registerStep1.html";
		     }
	    },
        error: function(data){
        	console.log("失败"+data);
        }     
	});
}